package teaching.io.advance;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

/**
 * 字节输出流到字符输出流的转换类的示例。
 * 
 * @author deng.zhao
 * @version 1.0 2018/03/28
 *
 */
public class OutputStreamWriterExample {

	public static void main(String[] args) {
		
		String str = "你好，世界。";

		try (OutputStream os = new FileOutputStream("d:/test.dat");
				OutputStreamWriter isr = new OutputStreamWriter(os);
				BufferedWriter bw = new BufferedWriter(isr);) {

			for (int i = 0; i < 10; i++) {
				bw.write(String.format("%2d. %s", i + 1, str));
				bw.newLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}

		System.out.println("DONE!");
	}
}
